package com.scaffold.card.service;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wangjg.commons.page.Page;

import com.scaffold.card.dao.CardDAO;
import com.scaffold.card.entity.Card;

@Service
@Transactional
public class CardService {

	@Autowired
	private CardDAO cardDAO;

	public Card getCard(Long id ) {
		return this.cardDAO.findById(id);
	}

	public void save(Card card){
		Timestamp now = new Timestamp(System.currentTimeMillis());
		if(card.getId()==null){
			card.setCreated(now);
			card.setModified(now);
			this.cardDAO.save(card);
		}else{
			card.setModified(now);
			this.cardDAO.update(card);
		}
	}

	public void update(Card card){
		Timestamp now = new Timestamp(System.currentTimeMillis());
		card.setModified(now);
		this.cardDAO.update(card);
	}

	public void delete(Card card){
		this.cardDAO.delete(card);
	}

	public List<Card> pageQuery(Page page, Long categoryId, String keyword) {
		return this.cardDAO.pageQuery(page, categoryId, keyword);
	}


}
